﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.PageControl
{
    public partial class HospitalLeft : BasePage
    {
        public string strURL = "";
        string strhid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                //add by 曹鹏 2011年5月7日15:42:29 取得当前用户
                lblCurrentUser.Text = HZ.Supervise.Web.Function.GetNowTime() + "&nbsp;&nbsp;<img alt='' src='../Images/ModalImageAh_New/smile.gif'/>&nbsp;&nbsp;" + CurrentAccount.GetUser().UserName;
                //取得当前用户角色
                this.lblCurrentRole.Text = CurrentAccount.GetUser().Org.OrgName;

                ViewState["query"] = URLUtil.GetSuperviseQueryFromURL(Request);
                //LoadHospitalType();
                bangdingHostial();
                strURL = "../Secondphase/ReportHospital/ReportOfHospitalFirstLevel.aspx";
            }
            else
            {
                strURL = "../Secondphase/ReportHospital/Blank.aspx";
            }
            //txtname.Attributes.Add("onkeydown", "if(event.keyCode==13){event.keyCode==13 ; document.getElementById('btnQuery').click();}");
        }

        protected void gvwselect_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string sessionid = Guid.NewGuid().ToString();
                SuperviseQuery query = new SuperviseQuery();
                query.HospitalName = e.Row.Cells[0].Text.Trim();
                Session[sessionid] = query;
                e.Row.Cells[0].Text = "<a  style=\"cursor:hand\" onclick=\"seturl('" + sessionid + "')\">" + e.Row.Cells[0].Text + "</a>";

            }
        }

        /// <summary>
        /// 绑定医院
        /// </summary>
        private void bangdingHostial()
        {
            HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
            string _HospitalID = DAL.DAL_Helper.Replace(txtname.Text.Trim());
            if (_HospitalID.Equals(""))
            {
                _HospitalID = "所有医院";
            }

            string strType = string.Empty;

            string str = CurrentAccount.GetUser().Org.Area.AreaID;

            int totalrecord = 0;
            //DataTable dt = pre.GetHospitalName_Type(_HospitalID, strType, CurrentAccount.GetUser().Org.Area.AreaID, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalrecord);
            DataTable dt = pre.GetHospitalName_Type(_HospitalID, CurrentAccount.GetUser().Org.Area.AreaID, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalrecord);
            AspNetPager1.RecordCount = totalrecord;
            gvwselect.DataSource = dt;
            gvwselect.DataBind();
        }

        /// <summary>
        /// 加载医院类别
        /// </summary>
        //private void LoadHospitalType()
        //{
        //    HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        //    this.dropType.DataSource = pre.GetHospitalType();
        //    this.dropType.DataTextField = "Levels";
        //    this.dropType.DataValueField = "Levels";
        //    this.dropType.DataBind();

        //    this.dropType.Items.Insert(0, new ListItem("所有类别"));
        //}

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bangdingHostial();
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void gvwselect_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                
                e.Row.Attributes.Add("onclick", "a(this);");
                
            }
        }

    }
}
